

$(function () {
    getTreeData();
});


function getTreeData() {
    $.ajax({
        headers:window.getRequestHears(true),
        type: "GET",
        url: window.API_SERVER_URL + "aipark/area/tree",
        headers: getRequestHears(),
        success: function (tree) {
            loadTree(tree);
        }
    });
}

function loadTree(tree) {
    $('#jstree').jstree({
        'core': {
            'data': tree
        },
        "plugins": ["search"]
    });
    $('#jstree').jstree().open_all();
}

$('#jstree').on("changed.jstree", function (e, data) {
	parent.$("#"+$("#idInput").val()).val(data.node.id);
	parent.$("#"+$("#nameInput").val()).val(data.node.text);
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
});

function cleanAll(){
	parent.$("#"+$("#idInput").val()).val('');
	parent.$("#"+$("#nameInput").val()).val('');
	var index = parent.layer.getFrameIndex(window.name);  
	parent.layer.close(index);
}
